{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "255723e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8b18235d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.4.13\n"
     ]
    }
   ],
   "source": [
    "print(ts.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1dab23b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Empty DataFrame\n",
      "Columns: [user_id, 到期时间, 到期积分]\n",
      "Index: []\n"
     ]
    }
   ],
   "source": [
    "\n",
    "pro = ts.pro_api()\n",
    "df = pro.user(token='0ba8feef618e5db7b1ebb65538fe51e4aef69fb3cbf709d44128f313')\n",
    "\n",
    "print(df)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "218b8521",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         ts_code  symbol      name list_date delist_date\n",
      "0     JD1907.DCE  JD1907    鸡蛋1907  20180727    20190726\n",
      "1     CS1505.DCE  CS1505  玉米淀粉1505  20141219    20150515\n",
      "2     JM2304.DCE  JM2304    焦煤2304  20220419    20230417\n",
      "3      C1003.DCE   C1003    玉米1003  20090316    20100312\n",
      "4      M1708.DCE   M1708    豆粕1708  20160815    20170814\n",
      "...          ...     ...       ...       ...         ...\n",
      "2754   Y2412.DCE   Y2412    豆油2412  20231215    20241213\n",
      "2755   P2406.DCE   P2406   棕榈油2406  20230615    20240617\n",
      "2756  JM1611.DCE  JM1611    焦煤1611  20151116    20161114\n",
      "2757  EG2405.DCE  EG2405   乙二醇2405  20230529    20240528\n",
      "2758   B1007.DCE   B1007    豆二1007  20090715    20100714\n",
      "\n",
      "[2759 rows x 5 columns]\n"
     ]
    }
   ],
   "source": [
    "df = pro.fut_basic(exchange='DCE', fut_type='1', fields='ts_code,symbol,name,list_date,delist_date')\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "71fe5213",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = \"E:\\\\HQData\\\\future\\\\\"\n",
    "\n",
    "\n",
    "df.to_csv(path + \"Contracts.csv\", encoding='UTF-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47d07c02",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
